﻿using System;
using System.Collections.Generic;
using System.Linq;
using Framework.Core.Dependency.Domain;
using log4net;

namespace Framework.Core.Dependency.Visitor
{
    internal class UnitTestVisitor : IVisitor<Project>
    {
        private readonly IList<Project> unitTestProjects;
        private static readonly ILog Logger = LogManager.GetLogger(typeof(UnitTestVisitor));

        public UnitTestVisitor(IEnumerable<Solution> campainSolutions)
        {
            unitTestProjects = campainSolutions.SelectMany(x => x.Projects).Where(p => p.IsUnitTest).ToList();
        }

        public void Visit(Project item)
        {
            if (unitTestProjects.Any(ut => string.Equals(item.AssemblyName, ut.AssemblyName, StringComparison.CurrentCultureIgnoreCase)))
            {
                Logger.InfoFormat("Project {0} is UnitTest project", item.AssemblyName);
                item.IsUnitTest = true;
            }
        }
    }
}